

jQuery(function ($) {
    var notice_id = window.location.href.split('=')[1];
    var params = {
        "Notice": {
            "id": notice_id
        }
    };

    send_ajax('post', '/get', params, function callback(result) {
        if (result.code == 200&& result.Notice) {
            var data = result.Notice;
            $('#location').append('<span>></span><h1>' + data.title + '</h1>\n\t\t\t');
            $('.left_content_top').append('<div class="left_content_title">\n\t\t\t<h3>\n\t\t\t\t' + data.title + "\n\t\t\t</h3>\n\t\t\t<p><span>\u66F4\u65B0\u65F6\u95F4:" + data.update_time + "</span><span>\u6587\u7AE0\u6765\u6E90\uFF1A\u6613\u4ECE\u7F51</span><span>\u6587\u7AE0\u4F5C\u8005\uFF1A\u3010\u6613\u4ECE\u7F51\u3011</span><span>\u70B9\u51FB\uFF1A " + (data.clicks + data.clicks_v) + "\n\t\t\t\t\t\u6B21</span></p>\n\t\t</div>\n\t\t<div class=\"left_content_detail\">\n\t\t\t<p>" + data.content + '\n\t\t\t</p>\n\t\t</div>');
        };
        notice();
    });

    function notice() {
        var notice_params = {
            "notice_id": 1
        };
        send_ajax('post', '/api/notice/last_next', notice_params, function callback(result) {

            if (result.code == 200&&result.data) {
                var data = result.data;

                $('.left_content_top').append('<div class="link_box">\n                    <p data-notice-id="' + (data.last != null ? data.last.id : "") + "\" >\u4E0A\u4E00\u7BC7\uFF1A" + (data.last != null ? data.last.title : "没有了") + ' </p>\n                    <p data-notice-id="' + (data.next != null ? data.next.id : "") + "\" >\u4E0B\u4E00\u7BC7\uFF1A" + (data.next != null ? data.next.title : "没有了") + '</p>\n                </div>');
            }
            $('.link_box p').click(function () {
                var id = $(this).attr('data-notice-id');
                if (id) {
                    window.location.href = "/notice/notice_detail.html?id=" + id;
                }
            });
        });
    }

    // var clickparams = {
    //     "Notice": {
    //         "id": notice_id,
    //         "clicks+": 1
    //     }
    // };
    // send_ajax('post', '/put', clickparams, function callback(res) {

    // });
    //咨询问答 右侧广告位
    var params = {
        "WebPage": {
            "page_sn": "notice_detail"
        },
        "AdPosition": {
            "position_sn": "bottom_article_ask_right"
        },
        "Ad": {
            "page_id@": "WebPage/id",
            "position_id@": "AdPosition/id"
        }
    };

    send_ajax('post', '/get', params, function callback(res) {

        var data = res.Ad;
        if (data) {
            $('.yc_content_pic').append('<a href="' + data.ad_link + '"  target="_blank"><img src="' + isImgHttp(data.img) + '" alt=""></a>');
        }
    });

    //咨询问答 上部广告位
    var params = {
        "WebPage": {
            "page_sn": "notice_detail"
        },
        "AdPosition": {
            "position_sn": "bottom_full"
        },
        "Ad": {
            "page_id@": "WebPage/id",
            "position_id@": "AdPosition/id",
            "page_holder_id": notice_id
        }
    };

    send_ajax('post', '/get', params, function callback(res) {

        var data = res.Ad;
        if (data) {
            $('.artist_pic_show').append('<a href="' + data.ad_link + '"  target="_blank"><img src="' + isImgHttp(data.img) + '" title="" alt="' + data.img_alt + '"></a>');
        } else {
            var params = {
                "WebPage": {
                    "page_sn": "notice_detail"
                },
                "AdPosition": {
                    "position_sn": "bottom_full"
                },
                "Ad": {
                    "page_id@": "WebPage/id",
                    "position_id@": "AdPosition/id"
                }
            };
            send_ajax('post', '/get', params, function callback(res) {
                if (res.Ad) {
                    var data = res.Ad;
                    $('.artist_pic_show').append('<a href="' + data.ad_link + '"  target="_blank"><img src="' + data.img + '" title="" alt="' + data.img_alt + '"></a>');
                }
            });
        }
    });
    //畜牧资讯
    var params = {
        "[]": {
            "count": 7,
            "Article": {
                "@order": "rank-"
            }
        }
    };
    send_ajax('post', '/get', params, function callback(res) {
        if (res.code == 200 && res["[]"]) {
            var data = res["[]"];
            var html = '';
            for (var i = 0; i < data.length; i++) {
                html += '<li><a href="/article-' + data[i].Article.id + '.html"  target="_blank">' + data[i].Article.title + '</a></li>';
            };
            $('#yc_article_list').html(html);
        }
    });
    //畜牧问答
    var params = {
        "[]": {
            "count": 7,
            "Ask": {
                "@order": "rank-"
            }
        }
    };
    send_ajax('post', '/get', params, function callback(res) {
        if (res.code == 200 && res["[]"]) {
            var data = res["[]"];
            var html = '';
            for (var i = 0; i < data.length; i++) {
                html += '<li><a href="/article-' + data[i].Ask.id + '.html" target="_blank">' + data[i].Ask.title + '</a></li>';
            };
            $('#yc_question_list').html(html);
        }
    });
});